package com.weixin.paleituo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.bean.UnitsBean;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

/**
 * Author yichao
 * Time  2017/12/1 0:38
 * Dest  售卖目录
 */

public class SaleStatusMenuRecyclerViewAdapter extends RecyclerView.Adapter<SaleStatusMenuRecyclerViewAdapter.ViewHolder> {

    private int checkPosition;
    private Context mContext;

    public void setList(List<UnitsBean> list) {
        mList = list;
    }

    private List<UnitsBean> mList;

    public SaleStatusMenuRecyclerViewAdapter(Context context, List<UnitsBean> list) {
        mContext = context;
        mList = list;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = UIUtils.inflate(mContext, R.layout.sale_status_menu_item_layout, parent, false);
        return new ViewHolder(view);
    }


    public void setCheckPostion(int postion){
        checkPosition=postion;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (checkPosition==position){
            holder.tvNemu.setSelected(true);
           holder.mLlitemRoot.setSelected(true);

        }else {
            holder.tvNemu.setSelected(false);
            holder.mLlitemRoot.setSelected(false);
        }
if (position==mList.size()-1){

    holder.viewline.setVisibility(View.INVISIBLE);

}else {
    holder.viewline.setVisibility(View.VISIBLE);

}
        holder.tvNemu.setText(mList.get(position).getUnit());

        if (mOnItemClickListener != null) {
            holder.mItemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(v, position);
                }
            });

        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private View mItemView;
        private TextView tvNemu;
        private LinearLayout mLlitemRoot;
        private View viewline;

        public ViewHolder(View itemView) {
            super(itemView);
            mItemView = itemView;
            tvNemu = mItemView.findViewById(R.id.tv_item_menu_sale_status_menu_item_layout);
            mLlitemRoot = mItemView.findViewById(R.id.ll_itemroot_sale_status_menu_item);

          viewline=  mItemView.findViewById(R.id.viewline_sale_status_menu_item_layout);




        }
    }

    private OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener {
        public void onClick(View v, int position);

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;

    }


}
